package addCompo.uiSheet
{
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	
	public class SheetButton extends MovieClip
	{
		//-----------------------------------------------------------------------------------
		// public vars
		//-----------------------------------------------------------------------------------
		public var defaultBtn : MovieClip;
		public var submitBtn : MovieClip;
		public var cancelBtn : MovieClip;
		public var deleteBtn : MovieClip;
		
		public var btnLabel : String;
		public var btnType 	: String;
		//-----------------------------------------------------------------------------------
		// protected / internal vars
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// private vars
		//-----------------------------------------------------------------------------------
		private var btnList : Vector.<MovieClip> = new Vector.<MovieClip>();
		
		//-----------------------------------------------------------------------------------
		// public functions
		//-----------------------------------------------------------------------------------	
		public function SheetButton( labelAndType : String )
		{
			super();
			
			//초기화
			btnList.push( defaultBtn, submitBtn, cancelBtn, deleteBtn );
			
			var i : int = 0;
			var len : int = btnList.length;
			while( i < len )
			{
				btnList[i].gotoAndStop( 1 );
				btnList[i].visible = false;
				btnList[i].addEventListener(MouseEvent.MOUSE_DOWN , onButtonDown );
				btnList[i].addEventListener(MouseEvent.MOUSE_UP , onButtonUp );
				btnList[i].addEventListener(MouseEvent.MOUSE_OUT , onButtonUp );
				++i;
			}
			
			var fontColor : uint = 0xffffff;
			var arrLabelAndType : Array = labelAndType.toLocaleLowerCase().split(",");
			btnLabel = arrLabelAndType[0];
			btnType  = arrLabelAndType[1];
			
			//버튼 타입 설정
			switch(btnType)
			{
				case '1'		: cancelBtn.visible 	= true;	break;
				case '2'		: submitBtn.visible 	= true;	break;
				case '3'		: deleteBtn.visible 	= true;	break;
				default: 
					defaultBtn.visible 	= true;
					fontColor = 0x000000;
					break;
			}
			
		}
		
		//-----------------------------------------------------------------------------------
		// private functions
		//-----------------------------------------------------------------------------------
		//-----------------------------------------------------------------------------------
		// event handler
		//-----------------------------------------------------------------------------------
		protected function onButtonDown(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			currentTarget.gotoAndStop( 2 );
		}
		
		protected function onButtonUp(e:MouseEvent):void
		{
			var currentTarget : MovieClip = e.currentTarget as MovieClip;
			currentTarget.gotoAndStop( 1 );
		}
	}
	
}